package org.jetnuke.modules.top;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.velocity.VelocityContext;
import org.jetnuke.common.ActionForward;
import org.jetnuke.common.IAction;
import org.jetnuke.common.IAdminInfo;
import org.jetnuke.common.IModuleInfo;
import org.jetnuke.common.IUserInfo;
import org.jetnuke.dao.DataAccessDriver;
import org.jetnuke.entities.MainConfig;

public class Top10 implements IAction {

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jetnuke.common.IAction#exec(javax.servlet.http.HttpServletRequest,
	 *      javax.servlet.http.HttpServletResponse,
	 *      org.apache.velocity.VelocityContext, org.jetnuke.common.IModuleInfo,
	 *      java.lang.String, org.jetnuke.common.IUserInfo,
	 *      org.jetnuke.common.IAdminInfo)
	 */
	public ActionForward exec(HttpServletRequest request,
			HttpServletResponse response, VelocityContext vc, IModuleInfo info,
			String op, IUserInfo ui, IAdminInfo ai) throws Exception {
		MainConfig mainConfig = (MainConfig) request
		.getAttribute("MAIN_CONFIG");
		int top=mainConfig.getTOP();
		vc.put("stories", 
				DataAccessDriver.getInst().newStoriesDAO().selectOrderByCounterDescLimit(top));
				//storiesPeer.doSelect(new Criteria()
				//.addDescendingOrderByColumn(storiesPeer.COUNTER).setLimit(10)));
		vc.put("voted_stories",
				DataAccessDriver.getInst().newStoriesDAO().selectVotedOrderScoreDesc(top));
				//storiesPeer.doSelect(new Criteria().add(
				//storiesPeer.SCORE, 0, Criteria.NOT_EQUAL)
				//.addDescendingOrderByColumn(storiesPeer.SCORE).setLimit(10)));
		//vc.put("rating_stories",STORIESPeer.doSelect(new
		// Criteria().add(STORIESPeer.SCORE,0,Criteria.EQUAL).addDescendingOrderByColumn(STORIESPeer.SCORE).setLimit(10)));
		vc
				.put("commented_stories", 
						DataAccessDriver.getInst().newStoriesDAO().selectCommentedOrderCommentDesc(top));
						//storiesPeer.doSelect(new Criteria()
						//.addDescendingOrderByColumn(storiesPeer.COMMENTS)
						//.setLimit(10)));
		vc.put("categories", 
				DataAccessDriver.getInst().newStoriesCatDAO().selectOrderCounterDesc(top));
				//stories_catPeer.doSelect(new Criteria()
				//.addDescendingOrderByColumn(stories_catPeer.COUNTER).setLimit(
				//		10)));
		vc.put("special_sections", 
				DataAccessDriver.getInst().newSeccontDAO().selectOrderCounterDesc(top));
				//seccontPeer.doSelect(new Criteria()
				//.addDescendingOrderByColumn(seccontPeer.COUNTER).setLimit(10)));
		//vc.put("users", usersPeer.doSelect(new Criteria()
				//.addDescendingOrderByColumn(usersPeer.COUNTER).setLimit(10)));
		//TODO
		//vc.put("authors", DataAccessDriver.getInst().newAuthorsModel().selectAll_order_COUNTER_desc());
		vc.put("reviews", 
				DataAccessDriver.getInst().newReviewsDAO().selectOrderHitsDesc(10));
				//reviewsPeer.doSelect(new Criteria()
				//.addDescendingOrderByColumn(reviewsPeer.HITS).setLimit(10)));
		vc.put("downloads",DataAccessDriver.getInst().newDownloadDownloadDAO().getByHitsDown(0,top));
				
				//downloads_downloadsPeer.doSelect(new Criteria()
				//.addDescendingOrderByColumn(downloads_downloadsPeer.HITS)
				//.setLimit(10)));
		vc.put("pages", 
				DataAccessDriver.getInst().newPagesDAO().selectOrderCounterDesc(top));
				//pagesPeer.doSelect(new Criteria()
				//.addDescendingOrderByColumn(pagesPeer.COUNTER).setLimit(10)));
		return new ActionForward(op, info);
	}

}
